package dhee.wtqshopproject.dao;

import dhee.wtqshopproject.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    // 新增商品
    @Insert("INSERT INTO product (category_id, name, price, stock, sales_volume, main_image, description, is_use,is_show, create_time) " +
            "VALUES (#{categoryId}, #{name}, #{price}, #{stock}, #{salesVolume}, #{mainImage}, #{description}, #{isUse},#{isShow}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "productId", keyColumn = "product_id")
    int insertProduct(Product product);
    // 逻辑删除（is_use置0）
    @Update("UPDATE product SET is_use = 0 WHERE product_id = #{productId}")
    int deleteProductById(Integer productId);
    // 修改商品信息
    @Update("UPDATE product SET " +
            "category_id = #{categoryId}, " +
            "name = #{name}, " +
            "price = #{price}, " +
            "stock = #{stock}, " +
            "sales_volume = #{salesVolume}, " +
            "main_image = #{mainImage}, " +
            "description = #{description}, " +
            "is_use = #{isUse}, " +
            "is_show = #{isShow} "  +
            "WHERE product_id = #{productId}")
    int updateProduct(Product product);
    // 根据ID查询商品
    @Select("SELECT * FROM product WHERE product_id = #{productId}")
    Product selectProductById(Integer productId);
    // 查询所有商品
    @Select("SELECT * FROM product ")
    List<Product> selectAllProducts();

}
